/** api接口定义
 * @file api.hpp
 * @author Kiven Lee
 * @version 1.0
 * @date 2021-08-26
 */
#pragma once

#include "klib_http/request.hpp"
#include "klib_http/server.hpp"

namespace ai {

    asio::awaitable<bool> pre_handler(klib::http::request_t& req);

    #define HTTP_API_FUNC(x) asio::awaitable<void> api_##x(klib::http::request_t& req)
        HTTP_API_FUNC(ping);
        HTTP_API_FUNC(login);
        HTTP_API_FUNC(list);
        HTTP_API_FUNC(post);
        HTTP_API_FUNC(del);
        HTTP_API_FUNC(exit);
        HTTP_API_FUNC(create);
        HTTP_API_FUNC(debug);
    #undef HTTP_API_FUNC
    // asio::awaitable<void> api_ping(klib::http::request_t& req);
    // asio::awaitable<void> api_login(klib::http::request_t& req);
    // asio::awaitable<void> api_list(klib::http::request_t& req);
    // asio::awaitable<void> api_post(klib::http::request_t& req);
    // asio::awaitable<void> api_del(klib::http::request_t& req);
    // asio::awaitable<void> api_exit(klib::http::request_t& req);
    // asio::awaitable<void> api_create(klib::http::request_t& req);

    /** api接口定义宏 */
    #define HTTP_API_MAP(x) {"/"#x, api_##x}
    /** api接口映射表 */
    constexpr klib::http::api_handler_t api_handlers[] = {
        HTTP_API_MAP(ping),
        HTTP_API_MAP(login),
        HTTP_API_MAP(list),
        HTTP_API_MAP(post),
        HTTP_API_MAP(del),
        HTTP_API_MAP(exit),
        HTTP_API_MAP(create),
        HTTP_API_MAP(debug),
    };
    #undef HTTP_API_MAP

} // namespace ai
